'''
Created on Nov 27, 2010

@author: philip
'''

from models import Event
from datetime import datetime

class AddEventRequest:
    def __init__(self,title,description,place,community,startDate,endDate):
        # expected date format dd/mm/yyyy
        self.title = title
        self.description = description
        self.place = place
        self.community = community
        self.startDate = self.__parseDate(startDate)
        self.endDate = self.__parseDate(endDate)
        
    def __parseDate(self,dateString):
        pieces = dateString.split("/")
        return datetime(int(pieces[2]),int(pieces[1]),int(pieces[0]))

class EventService:
    def __init__(self):
        pass
    
    def add(self,request):
        event = Event()
        event.title = request.title
        event.description = request.description
        event.place = request.place
        event.communityId = request.community
        event.startDate = request.startDate
        event.endDate = request.endDate
        event.save()
        return event
    
    def getUpcomingEvents(self):
        return Event.objects.filter(startDate__gte = datetime.today())